﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.Master" AutoEventWireup="true" CodeBehind="ManageNews.aspx.cs" Inherits="spk_eAuction.admin.ManageNews" enableViewStateMac="false" viewStateEncryptionMode="Never" enableEventValidation="false" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title> Quản trị - Quản lý tin tức</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphBody" runat="server">
    <center>
        <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
            <asp:View ID="View1" runat="server">
                <div class="fullwidth" >
                    <div class="content-head" > Danh sách tin tức</div>
                    <div class="content-body" > 
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                            DeleteCommand="DELETE FROM [News] WHERE [NewsID] = @NewsID" 
                            InsertCommand="INSERT INTO [News] ([ThumbnailUrl], [ImageUrl], [PostUser], [Priority], [Title], [Content], [PostDate]) VALUES (@ThumbnailUrl, @ImageUrl, @PostUser, @Priority, @Title, @Content, @PostDate)" 
                            SelectCommand="SELECT * FROM [News] ORDER BY [PostDate] DESC" 
                    
                            UpdateCommand="UPDATE [News] SET [ThumbnailUrl] = @ThumbnailUrl, [ImageUrl] = @ImageUrl, [PostUser] = @PostUser, [Priority] = @Priority, [Title] = @Title, [Content] = @Content, [PostDate] = @PostDate WHERE [NewsID] = @NewsID">
                            <DeleteParameters>
                                <asp:Parameter Name="NewsID" Type="Int32" />
                            </DeleteParameters>
                            <InsertParameters>
                                <asp:Parameter Name="ThumbnailUrl" Type="String" />
                                <asp:Parameter Name="ImageUrl" Type="String" />
                                <asp:Parameter Name="PostUser" DbType="Guid" />
                                <asp:Parameter Name="Priority" Type="Int32" />
                                <asp:Parameter Name="Title" Type="String" />
                                <asp:Parameter Name="Content" Type="String" />
                                <asp:Parameter Name="PostDate" Type="DateTime" />
                            </InsertParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="ThumbnailUrl" Type="String" />
                                <asp:Parameter Name="ImageUrl" Type="String" />
                                <asp:Parameter Name="PostUser" Type="Object" />
                                <asp:Parameter Name="Priority" Type="Int32" />
                                <asp:Parameter Name="Title" Type="String" />
                                <asp:Parameter Name="Content" Type="String" />
                                <asp:Parameter Name="PostDate" Type="DateTime" />
                                <asp:Parameter Name="NewsID" Type="Int32" />
                            </UpdateParameters>
                        </asp:SqlDataSource>    
                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                            CellPadding="4" DataKeyNames="NewsID" DataSourceID="SqlDataSource1" 
                            ForeColor="#333333" GridLines="None" onrowcommand="GridView1_RowCommand" 
                            AllowPaging="True" onrowdatabound="GridView1_RowDataBound" ShowFooter="True">
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:ImageButton ID="ImageButtonDetail" runat="server" 
                                            Height="20px" ImageUrl="~/images/items/detail.jpg" Width="20px" 
                                            CommandArgument='<%# Eval("NewsID") %>' onclick="ImageButtonDetail_Click"/>
                                        <asp:ImageButton ID="ImageButtonEdit" runat="server" 
                                            CommandArgument='<%# Eval("NewsID") %>' Height="20px" 
                                            ImageUrl="~/images/items/edit.jpg" Width="20px" 
                                            onclick="ImageButtonEdit_Click" />
                                        <asp:ImageButton ID="ImageButtonDelete" runat="server" CommandName="Delete" 
                                            Height="20px" ImageUrl="~/images/items/delete.jpg" Width="20px" 
                                            onclientclick="return confirm('Bạn có chắc là muốn xoá?');" />
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Thêm tin</asp:LinkButton>
                                    </FooterTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="NewsID" HeaderText="Mã tin" InsertVisible="False" 
                                    ReadOnly="True" SortExpression="NewsID" />
                                <asp:BoundField DataField="Title" HeaderText="Tiêu đề" 
                                    SortExpression="Title" />
                                <asp:TemplateField HeaderText="Ảnh nhỏ">
                                    <ItemTemplate>
                                        <asp:Image ID="Image1" runat="server" Height="50px" 
                                            ImageUrl='<%# Eval("ThumbnailUrl") %>' Width="50px" />
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("ThumbnailUrl") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Người đăng" SortExpression="PostUser">
                                    <ItemTemplate>
                                        <asp:DropDownList ID="DropDownList2" runat="server" 
                                            DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserId" 
                                            Enabled="False" SelectedValue='<%# Bind("PostUser") %>'>
                                        </asp:DropDownList>
                                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                            ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                                            SelectCommand="SELECT [UserId], [UserName] FROM [vw_aspnet_Users]">
                                        </asp:SqlDataSource>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("PostUser") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="PostDate" HeaderText="Ngày đăng" 
                                    SortExpression="PostDate" />
                                <asp:TemplateField HeaderText="Nội dung" SortExpression="Content">
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Content") %>'></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Content") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <EditRowStyle BackColor="#999999" />
                            <EmptyDataTemplate>
                                Không có dữ liệu
                                <br />
                                <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Thêm tin</asp:LinkButton>
                            </EmptyDataTemplate>
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#E9E7E2" />
                            <SortedAscendingHeaderStyle BackColor="#506C8C" />
                            <SortedDescendingCellStyle BackColor="#FFFDF8" />
                            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                        </asp:GridView>      
                    </div>
                    <div class="content-foot" > 
                
                    </div>
                </div>
                
            </asp:View>
            <asp:View ID="View2" runat="server">
                <div class="fullwidth" >
                    <div class="content-head" > Chi tiết tin tức</div>
                    <div class="content-body" > 
                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                            DeleteCommand="DELETE FROM [News] WHERE [NewsID] = @NewsID" 
                            InsertCommand="INSERT INTO [News] ([ThumbnailUrl], [ImageUrl], [PostUser], [Priority], [Title], [Content], [PostDate]) VALUES (@ThumbnailUrl, @ImageUrl, @PostUser, @Priority, @Title, @Content, @PostDate)" 
                            SelectCommand="SELECT * FROM [News] WHERE ([NewsID] = @NewsID)" 
                            UpdateCommand="UPDATE [News] SET [ThumbnailUrl] = @ThumbnailUrl, [ImageUrl] = @ImageUrl, [PostUser] = @PostUser, [Priority] = @Priority, [Title] = @Title, [Content] = @Content, [PostDate] = @PostDate WHERE [NewsID] = @NewsID">
                            <DeleteParameters>
                                <asp:Parameter Name="NewsID" Type="Int32" />
                            </DeleteParameters>
                            <InsertParameters>
                                <asp:Parameter Name="ThumbnailUrl" Type="String" />
                                <asp:Parameter Name="ImageUrl" Type="String" />
                                <asp:Parameter Name="PostUser" DbType="Guid" />
                                <asp:Parameter Name="Priority" Type="Int32" />
                                <asp:Parameter Name="Title" Type="String" />
                                <asp:Parameter Name="Content" Type="String" />
                                <asp:Parameter Name="PostDate" Type="DateTime" />
                            </InsertParameters>
                            <SelectParameters>
                                <asp:Parameter Name="NewsID" Type="Int32" />
                            </SelectParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="ThumbnailUrl" Type="String" />
                                <asp:Parameter Name="ImageUrl" Type="String" />
                                <asp:Parameter Name="PostUser" DbType="Guid" />
                                <asp:Parameter Name="Priority" Type="Int32" />
                                <asp:Parameter Name="Title" Type="String" />
                                <asp:Parameter Name="Content" Type="String" />
                                <asp:Parameter Name="PostDate" Type="DateTime" />
                                <asp:Parameter Name="NewsID" Type="Int32" />
                            </UpdateParameters>
                        </asp:SqlDataSource>
                        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                                    CellPadding="4" DataKeyNames="NewsID" DataSourceID="SqlDataSource2" 
                                    ForeColor="#333333" GridLines="None" Height="50px" Width="580px" 
                                    DefaultMode="Insert" onitemcommand="DetailsView1_ItemCommand" 
                                    oniteminserted="DetailsView1_ItemInserted" 
                                    onitemupdated="DetailsView1_ItemUpdated" >
                                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                    <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                                    <EditRowStyle BackColor="#999999" />
                                    <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
                                    <Fields>
                                        <asp:TemplateField SortExpression="NewsID" HeaderText="Mã tin" 
                                            InsertVisible="False">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("NewsID") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("NewsID") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Tiêu đề" SortExpression="Title">
                                            <EditItemTemplate>
                                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                                    ControlToValidate="TextBox1" ErrorMessage="*" SetFocusOnError="True">Trường bắt buộc</asp:RequiredFieldValidator>
                                            </EditItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                                    ControlToValidate="TextBox1" ErrorMessage="*" SetFocusOnError="True">Trường bắt buộc</asp:RequiredFieldValidator>
                                            </InsertItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField> 
                                        <asp:TemplateField HeaderText="Ảnh nhỏ" SortExpression="ThumbnailUrl">
                                            <ItemTemplate>
                                                <asp:Image ID="Image2" runat="server" Height="70px" 
                                                    ImageUrl='<%# Bind("ThumbnailUrl") %>' Width="70px" />
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:Image ID="Image2" runat="server" Height="70px" 
                                                    ImageUrl='<%# Bind("ThumbnailUrl") %>' Width="70px" />
                                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ThumbnailUrl") %>'></asp:TextBox>
                                        
                                                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="false" 
                                                    Text="Nạp hình" CommandName="ImageLoad2" onclick="LinkButton2_Click" ></asp:LinkButton>
                                            </EditItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:Image ID="Image2" runat="server" Height="70px" 
                                                    ImageUrl='<%# Bind("ThumbnailUrl") %>' Width="70px" />
                                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ThumbnailUrl") %>'></asp:TextBox>
                                                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                                    CommandName="ImageLoad2" onclick="LinkButton2_Click">Nạp hình</asp:LinkButton>
                                            </InsertItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Ảnh lớn" SortExpression="ImageUrl">
                                            <ItemTemplate>
                                                <asp:Image ID="Image3" runat="server" Height="150px" 
                                                    ImageUrl='<%# Bind("ImageUrl") %>' Width="150px" />
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:Image ID="Image3" runat="server" Height="150px" 
                                                    ImageUrl='<%# Bind("ImageUrl") %>' Width="150px" />
                                                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ImageUrl") %>'></asp:TextBox>
                                                <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" 
                                                    CommandName="ImageLoad3" onclick="LinkButton3_Click">Nạp hình</asp:LinkButton>
                                            </EditItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:Image ID="Image3" runat="server" Height="150px" 
                                                    ImageUrl='<%# Bind("ImageUrl") %>' Width="150px" />
                                                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ImageUrl") %>'></asp:TextBox>
                                                <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" 
                                                    CommandName="ImageLoad3" onclick="LinkButton3_Click">Nạp hình</asp:LinkButton>
                                            </InsertItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Người đăng" SortExpression="PostUser">
                                            <EditItemTemplate>
                                                <asp:DropDownList ID="DropDownList1" runat="server" 
                                                    DataSourceID="SqlDataSource3" DataTextField="UserName" DataValueField="UserId" 
                                                    Enabled="False" SelectedValue='<%# Bind("PostUser") %>'>
                                                </asp:DropDownList>
                                                <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                                                    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                                                    SelectCommand="SELECT [UserId], [UserName] FROM [vw_aspnet_Users]">
                                                </asp:SqlDataSource>
                                            </EditItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:DropDownList ID="DropDownList1" runat="server" 
                                                    DataSourceID="SqlDataSource3" DataTextField="UserName" DataValueField="UserId" 
                                                    Enabled="False" SelectedValue='<%# Bind("PostUser") %>'>
                                                </asp:DropDownList>
                                                <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                                                    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                                                    SelectCommand="SELECT [UserId], [UserName] FROM [vw_aspnet_Users]">
                                                </asp:SqlDataSource>
                                            </InsertItemTemplate>
                                            <ItemTemplate>
                                                <asp:DropDownList ID="DropDownList1" runat="server" 
                                                    DataSourceID="SqlDataSource3" DataTextField="UserName" DataValueField="UserId" 
                                                    Enabled="False" SelectedValue='<%# Bind("PostUser") %>'>
                                                </asp:DropDownList>
                                                <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                                                    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                                                    SelectCommand="SELECT [UserId], [UserName] FROM [vw_aspnet_Users]">
                                                </asp:SqlDataSource>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Ngày đăng" SortExpression="PostDate">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label6" runat="server" Text='<%# Bind("PostDate") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:Label ID="Label6" runat="server" Text='<%# Bind("PostDate") %>'></asp:Label>
                                            </InsertItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label6" runat="server" Text='<%# Bind("PostDate") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="Priority" HeaderText="Priority" 
                                            SortExpression="Priority" Visible="False" />
                                        <asp:TemplateField HeaderText="Nội dung" SortExpression="Content">
                                            <EditItemTemplate>
                                                <cc1:Editor ID="Editor1" runat="server" Content='<%# Bind("Content") %>' 
                                                    Height="300px" Width="500px" />
                                            </EditItemTemplate>
                                            <InsertItemTemplate>
                                                <cc1:Editor ID="Editor1" runat="server" Content='<%# Bind("Content") %>' 
                                                    Height="300px" Width="500px" />
                                            </InsertItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label7" runat="server" Text='<%# Bind("Content") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <EditItemTemplate>
                                                <asp:LinkButton ID="LinkButton5" runat="server" CommandName="Update">Cập nhật</asp:LinkButton>
                                                <asp:LinkButton ID="LinkButton6" runat="server" CausesValidation="False" 
                                                    CommandName="Cancel">Huỷ</asp:LinkButton>
                                            </EditItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:LinkButton ID="LinkButton7" runat="server" CommandName="Insert">Thêm</asp:LinkButton>
                                                <asp:LinkButton ID="LinkButton8" runat="server" CausesValidation="False" 
                                                    CommandName="Cancel">Huỷ</asp:LinkButton>
                                            </InsertItemTemplate>
                                            <ItemTemplate>
                                                <asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" 
                                                    CommandName="_cancel">Quay về</asp:LinkButton>
                                            </ItemTemplate>
                                        </asp:TemplateField> 
                                    </Fields>
                                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                </asp:DetailsView>
                    </div>
                    <div class="content-foot" > 
                
                    </div>
            </asp:View>
        </asp:MultiView>
        
    </center>
</asp:Content>
